package com.groupbuying.sysconfig.intercepter;



import com.groupbuying.sysconfig.constants.SysconfigPlatformInfoEnumConstants;
import com.groupbuying.sysconfig.constants.WechatAliCommonConstans;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Vincentxin
 * @Date 2019/10/16
 */
public class ConfigurationStrategyFactorey {
    //自己先创建对象
    private static ConfigurationStrategyFactorey factory = new ConfigurationStrategyFactorey();
    //私有化构造器
    private ConfigurationStrategyFactorey(){

    }
    //创建初始化容器
    public  static Map<String,String> strategyMap = new HashMap<>();

    //静态代码块初始化容器
    static{
        strategyMap.put(WechatAliCommonConstans.WECHAT_MINI_APP_ROUTING, SysconfigPlatformInfoEnumConstants.ENUM_TAG_MINIWECHAT);
        strategyMap.put(WechatAliCommonConstans.WECHAT_PUBLIC_APP_ROUTING, SysconfigPlatformInfoEnumConstants.ENUM_TAG_PUBLICWECHAT);
        strategyMap.put(WechatAliCommonConstans.ALI_MINI_APP_ROUTING, SysconfigPlatformInfoEnumConstants.ENUM_TAG_MINIALI);
        strategyMap.put(WechatAliCommonConstans.ALI_PUBLIC_APP_ROUTING, SysconfigPlatformInfoEnumConstants.ENUM_TAG_PUBLICALI);
    }
    public static ConfigurationStrategyFactorey getInstance() {
        return factory;
    }

    public String selector(String path) {
        String key =null;
        for (String routing:strategyMap.keySet()){
            if (path.contains(routing)){
                key = routing;
                break;
            }
        }
        return strategyMap.get(key)==null? null:strategyMap.get(key);
    }


}
